/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pojo;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author alessandro
 */
@Entity
@Table(name = "DOUTOR")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Doutor.findAll", query = "SELECT d FROM Doutor d"),
    @NamedQuery(name = "Doutor.findByIdDoutor", query = "SELECT d FROM Doutor d WHERE d.idDoutor = :idDoutor"),
    @NamedQuery(name = "Doutor.findByNome", query = "SELECT d FROM Doutor d WHERE d.nome like :nome"),
    @NamedQuery(name = "Doutor.findByHorarioTrabInicial", query = "SELECT d FROM Doutor d WHERE d.horarioTrabInicial = :horarioTrabInicial"),
    @NamedQuery(name = "Doutor.findByHorarioTrabFinal", query = "SELECT d FROM Doutor d WHERE d.horarioTrabFinal = :horarioTrabFinal"),
    @NamedQuery(name = "Doutor.findByCro", query = "SELECT d FROM Doutor d WHERE d.cro = :cro")})
public class Doutor implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_doutor")
    private Integer idDoutor;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "nome")
    private String nome;
    @Column(name = "horario_trab_inicial")
    @Temporal(TemporalType.TIME)
    private Date horarioTrabInicial;
    @Column(name = "horario_trab_final")
    @Temporal(TemporalType.TIME)
    private Date horarioTrabFinal;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CRO")
    private Integer cro;
    @OneToMany(mappedBy = "codDoutor")
    private List<Agendamento> agendamentoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codDoutor")
    private List<Orcamento> orcamentoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codDoutor")
    private List<Excessao> excessaoList;
    @Transient
    private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

    public Doutor() {
    }

    public Doutor(Integer idDoutor) {
        this.idDoutor = idDoutor;
    }

    public Doutor(Integer idDoutor, String nome, Date horarioTrabInicial, Date horarioTrabFinal, int cro) {
        this.idDoutor = idDoutor;
        this.nome = nome;
        this.horarioTrabInicial = horarioTrabInicial;
        this.horarioTrabFinal = horarioTrabFinal;
        this.cro = cro;
    }

    public Integer getIdDoutor() {
        return idDoutor;
    }

    public void setIdDoutor(Integer idDoutor) {
        this.idDoutor = idDoutor;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        System.out.println("entro lol");
        this.nome = nome;
    }

    public Date getHorarioTrabInicial() {
        return horarioTrabInicial;
    }

    public void setHorarioTrabInicial(Date horarioTrabInicial) {
        this.horarioTrabInicial = horarioTrabInicial;
    }

    public Date getHorarioTrabFinal() {
        return horarioTrabFinal;
    }

    public void setHorarioTrabFinal(Date horarioTrabFinal) {
        this.horarioTrabFinal = horarioTrabFinal;
    }

    public Integer getCro() {
        return cro;
    }

    public void setCro(Integer cro) {
        this.cro = cro;
    }

    @XmlTransient
    public List<Agendamento> getAgendamentoList() {
        return agendamentoList;
    }

    public void setAgendamentoList(List<Agendamento> agendamentoList) {
        this.agendamentoList = agendamentoList;
    }

    @XmlTransient
    public List<Orcamento> getOrcamentoList() {
        return orcamentoList;
    }

    public void setOrcamentoList(List<Orcamento> orcamentoList) {
        this.orcamentoList = orcamentoList;
    }

    @XmlTransient
    public List<Excessao> getExcessaoList() {
        return excessaoList;
    }

    public void setExcessaoList(List<Excessao> excessaoList) {
        this.excessaoList = excessaoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idDoutor != null ? idDoutor.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Doutor)) {
            return false;
        }
        Doutor other = (Doutor) object;
        if ((this.idDoutor == null && other.idDoutor != null) || (this.idDoutor != null && !this.idDoutor.equals(other.idDoutor))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return nome;
    }
    
    public String getHoraInicialFormatada(){
        return sdf.format(this.getHorarioTrabInicial());
    }
    
    public String getHoraFinalFormatada(){
        return sdf.format(this.getHorarioTrabFinal());
    }
}
